# encoding: utf-8
require File.dirname(__FILE__) + '/../../lib/utils'

# GPS供应商对象
class Supplier < ActiveRecord::Base
  validates :name, :presence => true
  validates :key, :presence => true, :uniqueness => true
  validates :code, :presence => true, :uniqueness => true
  scope :in_use, where(:renounce_mark => 0)

  # 检查GPS数据是否合法
  # [gps_data] 供应商发来的GPS数据
  # [timestamp] 供应商本次发送的世间戳
  # [sign] 数据签名
  def gps_data?(gps_data, timestamp, sign)
    #TODO校验数据是否合法
    true
  end

  # 分发GPS数据
  # [gps_data] GPS供应商发送的GPS数据
  def dispatch(gps_data)
    logger.info "start dispatching ..."
    mq = Opal::Mq::Mq.new('Q_DISPATCH')
    mq.set gps_data
    #mq = Starling.new("localhost:22122" )
    #mq.set('q_dispatcher', gps_data)
    logger.info "dispatch successful."
  end
end
